package 消费者与生产者模式练习.Test01;

import java.util.List;

public class Production implements Runnable {
    private List list;

    public Production(List list) {
        this.list = list;
    }

    @Override
    public void run() {
        int i = 0;
        while (true){
            synchronized (list){
                if (list.size() <= 3){
                    list.add(++i);
                    try {
                        list.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    list.notify();
                }
                if (list.size() > 3){
                    try {
                        list.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                list.notify();
            }
        }
    }
}
